# -*- coding:utf-8 -*-
from cnocr import CnOcr
import time
import numpy as np
from PIL import ImageGrab, Image

time.sleep(4)

ocr = CnOcr()
time1 = time.time()
imButton1 = ImageGrab.grab(
    bbox=(1769, 6, 1876, 19))  # X1,Y1,X2,Y2
# imButton1 = ImageGrab.grab(
#     bbox=(354, 116, 511, 137))  # X1,Y1,X2,Y2
imButton1_numpy = np.array(imButton1.getdata(), dtype='uint8').reshape(
    (imButton1.size[1], imButton1.size[0], 3))
imButton1_pil = Image.fromarray(imButton1_numpy)
rButton1, gButton1, bButton1 = imButton1_pil.split()  # 分离三通道
obj1 = np.asarray(bButton1)
res = ocr.ocr(obj1)
for each in res:
    if ''.join(each) != '<blank>':
        print(''.join(each))
time2 = time.time()
print('本次图片识别总共耗时%s s' % (time2 - time1))
